package com.hzpd.hainan.module.newspager;

import android.os.Bundle;
import android.os.PersistableBundle;
import android.support.annotation.Nullable;
import android.view.KeyEvent;
import android.view.View;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;

import com.hzpd.hainan.R;
import com.hzpd.hainan.api.InterfaceJsonfile;
import com.hzpd.hainan.app.BaseActivity;
import com.hzpd.hainan.app.ToolBarActivity;
import com.hzpd.hainan.config.CODE;

import butterknife.BindView;

/**
 * Created by Administrator on 2018/11/19.
 */

public class NewsPaperDetailActivity extends ToolBarActivity{

    private WebView szb_webview;
    private String url;
    private String name;
    @Override
    public void initView() {
        super.initView();
        url = getIntent().getStringExtra("url");
        szb_webview = (WebView) findViewById(R.id.szb_webview);
        WebSettings webSettings = szb_webview.getSettings();
        webSettings.setJavaScriptEnabled(true);
        webSettings.setSupportZoom(true);//设置缩放
        webSettings.setBuiltInZoomControls(true);//设置出现缩放工具

        webSettings.setUseWideViewPort(true);//扩大比例的缩放
        //自适应屏幕
        webSettings.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.SINGLE_COLUMN);
        webSettings.setLoadWithOverviewMode(true);
        szb_webview.setWebViewClient(new WebViewClient());
        szb_webview.setOnKeyListener(new View.OnKeyListener() {
            @Override
            public boolean onKey(View view, int keyCode, KeyEvent keyEvent) {
                if (keyEvent.getAction() == KeyEvent.ACTION_DOWN) {
                    if (keyCode == KeyEvent.KEYCODE_BACK && szb_webview.canGoBack()) {
                        //表示按返回键 时的操作
                        szb_webview.goBack(); //后退
                        return true; //已处理 ...
                    }

                }
                return false;
            }
        });
        if(spu.getLanguage().equals(CODE.ZHONGWEN)) {
            szb_webview.loadUrl(url);
        }else{
            szb_webview.loadUrl(url);
        }
    }

    @Override
    public String initToolBarTitle() {
        name = getIntent().getStringExtra("name");
        return name;
    }

    @Override
    public int setMyContentView() {
        return R.layout.fragment_szb_layout;
    }
}
